#include <iostream>
#include <ctime>

#define DBG_LEVEL 0
#define INF_LEVEL 1
#define ERR_LEVEL 2
#define DEFAULT_LEVEL DBG_LEVEL

// 结尾+反斜杠是将换行符进行转义(宏定义不能存在换行)
// strftime将时间转为字符串
// ##__VA_ARGS__表示可变参数列表，##用于处理没有可变参数传递导致多出来一个逗号的问题
#define LOG(lev_str, level, format, ...){\
    if(level >= DEFAULT_LEVEL){\
        time_t t = time(nullptr);\
        struct tm *ptm = localtime(&t);\
        char time_str[32];\
        strftime(time_str, 31, "%H:%M:%S", ptm);\
        printf("[%s][%s][%s:%d]\t" format "\n", lev_str, time_str, __FILE__, __LINE__, ##__VA_ARGS__);\
    }\
}

#define DLOG(format, ...) LOG("DBG", DBG_LEVEL, format, ##__VA_ARGS__)
#define ILOG(format, ...) LOG("INF", INF_LEVEL, format, ##__VA_ARGS__)
#define ELOG(format, ...) LOG("ERR", ERR_LEVEL, format, ##__VA_ARGS__)

int main()
{
    // LOG("XXX", DBG_LEVEL, "Hello World--%d", 1);
    DLOG("Hello World--%d", 2);
    return 0;
}